/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.bean.BbsArticleBean;
import com.minierp.model.BbsArticle;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class BbsArticleValidator implements Validator {
	public boolean supports(Class clazz) {
		return BbsArticleBean.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		BbsArticleBean bean = (BbsArticleBean) obj;
		BbsArticle form = bean.getBbsArticle();
		if (form.getParentId() != 0L || form.getTitle() != null
				&& !form.getTitle().equals("")) {
			if (form.getContent() != null && !form.getContent().equals("")) {
				if (form.getContent() != null
						&& form.getContent().length() > 30000) {
					errors.rejectValue("bbsArticle.content", "",
							"『备注』不能超过30000个字");
				}
			} else {
				errors.rejectValue("bbsArticle.content", "", "请输入『备注』");
			}
		} else {
			errors.rejectValue("bbsArticle.title", "", "请输入『标题』");
		}

	}
}